// miniprogram/pages/articleList/articleList.js
Page({

  /**
   * Page initial data
   */
  data: {
    articleObjList : []
  },
  
  retrieveTargetArticleList() {
    const eventChannel = this.getOpenerEventChannel();
    eventChannel.on('receiveSpecialMomentID', (data) => {
      let specMomentID = data.specMomentID;

      let queryRequest = {
          originCollection : "Article",
          fromCollectionsLookUpParmas : [
                                    {
                                      name : "User",
                                      let : {
                                        userID : '$userID'
                                      },
                                      pipeline : [
                                        {
                                          operator : 'eq',
                                          fieldName : '$userID',
                                          definedName : '$$userID'
                                        },                                 
                                      ],
                                      project : {
                                        _id: 0,
                                        nickName: 1,
                                        avatar: 1              
                                      },
                                      as : 'Article2User',
                                    }
                                  ],
          matchCondition : {
            matchFieldName : 'specMomentID',
            operator : 'eq',
            value : specMomentID
          }
      }

      wx.cloud.callFunction({
        name : "AggregatedLookUpQuery",
        data : {
          queryRequest
        }
      })
      .then(res => {
        let articleObjList = res.result;
        console.log("Retrieve target article list ========== 返回结果原始数据：" + articleObjList);

        this.setData({
          articleObjList
        });
      });

    });
  },

  /**
   * Lifecycle function--Called when page load
   */
  onLoad: function (options) {
    //console.log(`options =========== ${options}`);

    //Retrieve the target Article list depends on the delivered Special Moment ID
    this.retrieveTargetArticleList();

    
  },

  /**
   * Lifecycle function--Called when page is initially rendered
   */
  onReady: function () {

  },

  /**
   * Lifecycle function--Called when page show
   */
  onShow: function () {

  },

  /**
   * Lifecycle function--Called when page hide
   */
  onHide: function () {

  },

  /**
   * Lifecycle function--Called when page unload
   */
  onUnload: function () {

  },

  /**
   * Page event handler function--Called when user drop down
   */
  onPullDownRefresh: function () {

  },

  /**
   * Called when page reach bottom
   */
  onReachBottom: function () {

  },

  /**
   * Called when user click on the top right corner to share
   */
  onShareAppMessage: function () {

  }
})